package com.headingdata.exercise;

import java.util.Random;
import java.util.Scanner;

public class Test6 {

    public static void main(String[] args) {
        //抢红包 5人抢9,666,188,520,99999五个红包，先到先得，一个红包只能抽中一次，先抽后抽都是随机的
        int[] arr = {9,666,188,520,99999};
//        prizeDraw(arr);
        start(arr);
    }
    public static void prizeDraw(int[] moneys){
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        for (int i = 0; i < moneys.length; i++) {
            System.out.println("请输入任意内容抽奖：");
            scan.next();
            while (true) {
                int index = random.nextInt(moneys.length);
                if(moneys[index] != 0){
                    System.out.println("恭喜您抽中红包:" + moneys[index]);
                    moneys[index] = 0;
                    break;
                }
            }

        }
    }

    public static void start(int[] moneys){
        Random r = new Random();
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < moneys.length; i++) {
            int index = r.nextInt(moneys.length);
            int temp = moneys[i];
            moneys[i] = moneys[index];
            moneys[index] = temp;
        }
        for (int i = 0; i < moneys.length; i++) {
            System.out.println("请输入任意内容抽奖：");
            scanner.next();
            System.out.println("恭喜您抽中红包："+moneys[i]);
        }
    }
}
